﻿@model CustomerInfoModel
@using Nop.Web.Models.Customer;
@using Nop.Core;
@{
    Layout = "~/Views/Shared/_ColumnsTwo.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Account").Text);
}
@section left
{
    @Html.Action("CustomerNavigation", "Customer", new { selectedTabId = CustomerNavigationEnum.Info })
}
@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script type="text/javascript">
        $(function () {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function () {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                var statesProgress = $("#states-loading-progress");
                statesProgress.show();
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.RouteUrl("GetStatesByCountryId"))",
                    data: { "countryId": selectedItem, "addSelectStateItem": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function (id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        statesProgress.hide();
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert('Failed to retrieve states.');
                        statesProgress.hide();
                    }
                });
            });
        });
    </script>
}
<div class="panel panel-default form-panel">
    <div class="panel-heading">
        <h3>@T("Account.MyAccount") - @T("Account.CustomerInfo")</h3>
    </div>
    <div class="panel-body">
        @using (Html.BeginForm())
        {
            @Html.AntiForgeryToken()
            <div class="message-error">
                @Html.ValidationSummary(true)
            </div>
            <div class="fieldset">
                    <legend>@T("Account.YourPersonalDetails")</legend>
                <div class="form-fields">
                    @if (Model.GenderEnabled)
                    {
                        <div class="form-group row">
                            <label class="col-md-2 control-label">@T("Account.Fields.Gender"):</label>
                            <div class="col-md-9">
                                @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "gender-male" })
                                <label class="forcheckbox" for="gender-male">@T("Account.Fields.Gender.Male")</label>
                                @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "gender-female" })
                                <label class="forcheckbox" for="gender-female">@T("Account.Fields.Gender.Female")</label>
                            </div>
                        </div>
                    }
                    <div class="form-group row">
                        @Html.LabelFor(model => model.FirstName, new { @class = "col-md-2 control-label" }, ":")
                        <div class="col-md-6">
                            @Html.TextBoxFor(model => model.FirstName, new { @class = "form-control" })
                        </div>
                        <div class="col-md-4">
                            @Html.RequiredHint()
                            @Html.ValidationMessageFor(model => model.FirstName)
                        </div>
                    </div>
                    <div class="form-group row">
                        @Html.LabelFor(model => model.LastName, new { @class = "col-md-2 control-label" }, ":")
                        <div class="col-md-6">
                            @Html.TextBoxFor(model => model.LastName, new { @class = "form-control" })
                        </div>
                        <div class="col-md-4">
                            @Html.RequiredHint()
                            @Html.ValidationMessageFor(model => model.LastName)
                        </div>
                    </div>
                    @if (Model.DateOfBirthEnabled)
                    {
                        <div class="form-group row">
                            <label class="col-md-2 control-label">@T("Account.Fields.DateOfBirth"):</label>
                            <div class="col-md-10">
                                @Html.DatePickerDropDowns(Html.FieldNameFor(x => x.DateOfBirthDay),
                                                          Html.FieldNameFor(x => x.DateOfBirthMonth),
                                                          Html.FieldNameFor(x => x.DateOfBirthYear),
                                                          DateTime.Now.Year - 110,
                                                          DateTime.Now.Year,
                                                          Model.DateOfBirthDay,
                                                          Model.DateOfBirthMonth,
                                                          Model.DateOfBirthYear)
                                @Html.ValidationMessageFor(model => model.DateOfBirthDay)
                                @Html.ValidationMessageFor(model => model.DateOfBirthMonth)
                                @Html.ValidationMessageFor(model => model.DateOfBirthYear)
                            </div>
                        </div>
                    }
                    <div class="form-group row">
                        @Html.LabelFor(model => model.Email, new { @class = "col-md-2 control-label" }, ":")
                        <div class="col-md-6">
                            @Html.TextBoxFor(model => model.Email, new { @class = "form-control" })
                        </div>
                        <div class="col-md-4">
                            @Html.RequiredHint()
                            @Html.ValidationMessageFor(model => model.Email)
                        </div>
                    </div>
                    @if (Model.UsernamesEnabled)
                    {
                        if (Model.AllowUsersToChangeUsernames)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Username, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.TextBoxFor(model => model.Username, new { @class = "form-control" })
                                </div>
                                <div class="col-md-4">
                                    @Html.RequiredHint()
                                    @Html.ValidationMessageFor(model => model.Username)
                                    @if (Model.CheckUsernameAvailabilityEnabled)
                                    {
                                        @Html.Partial("_CheckUsernameAvailability")
                                    }
                                </div>
                            </div>
                        }
                        else
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Username, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-10">
                                    @Model.Username
                                </div>
                            </div>
                        }
                    }
                </div>
            </div>
            if (Model.CompanyEnabled || Model.DisplayVatNumber)
            {
                <div class="fieldset">
                    <legend>@T("Account.CompanyDetails")</legend>
                    <div class="form-fields">
                        @if (Model.CompanyEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Company, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.Company)
                                </div>
                                <div class="col-md-6">
                                    @if (Model.CompanyRequired)
                                    {
                                        @Html.RequiredHint()

                                    }
                                    @Html.ValidationMessageFor(model => model.Company)
                                </div>
                            </div>
                        }
                        @if (Model.DisplayVatNumber)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.VatNumber, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.VatNumber)
                                </div>
                                <div class="col-md-4">
                                    <span class="vat-status">@Model.VatNumberStatusNote</span>
                                    <span class="vat-note"><em>@T("Account.Fields.VatNumber.Note")</em></span>
                                </div> 
                            </div>
                        }
                    </div>
                </div>
            }
            if (Model.StreetAddressEnabled ||
                        Model.StreetAddress2Enabled ||
                        Model.ZipPostalCodeEnabled ||
                        Model.CityEnabled ||
                        Model.CountryEnabled)
            {
                <div class="fieldset">
                    <legend>@T("Account.YourAddress")</legend>
                    <div class="form-fields">
                        @if (Model.StreetAddressEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.StreetAddress, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.StreetAddress)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.StreetAddressRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.StreetAddress)
                                </div>                             
                            </div>
                        }
                        @if (Model.StreetAddress2Enabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.StreetAddress2, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.StreetAddress2)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.StreetAddress2Required)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.StreetAddress2)
                                </div>       
                            </div>
                        }
                        @if (Model.ZipPostalCodeEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.ZipPostalCode, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.ZipPostalCode)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.ZipPostalCodeRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.ZipPostalCode)
                                </div>
                            </div>
                        }
                        @if (Model.CityEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.City, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.City)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.CityRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.City)
                                </div>
                            </div>
                        }
                        @if (Model.CountryEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.CountryId, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                @Html.DropDownList("CountryId", Model.AvailableCountries)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.CountryRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.CountryId)
                                </div>
                            </div>
                        }
                        @if (Model.CountryEnabled && Model.StateProvinceEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.StateProvinceId, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.DropDownList("StateProvinceId", Model.AvailableStates)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.StateProvinceRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.StateProvinceId)
                                    <span id="states-loading-progress" style="display: none;" class="please-wait">@T("Common.Wait...")</span>
                                </div>     
                            </div>
                        }
                    </div>
                </div>
            }
            if (Model.PhoneEnabled || Model.FaxEnabled)
            {
                <div class="fieldset">
                    <legend>@T("Account.YourContactInformation")</legend>
                    <div class="form-fields">
                        @if (Model.PhoneEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Phone, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.Phone)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.PhoneRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.Phone)
                                </div>
                            </div>
                        }
                        @if (Model.FaxEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Fax, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.Fax)
                                </div>
                                <div class="col-md-4">
                                    @if (Model.FaxRequired)
                                    {
                                        @Html.RequiredHint()
                                    }
                                    @Html.ValidationMessageFor(model => model.Fax)
                                </div>
                            </div>
                        }
                    </div>
                </div>
            }
            if (Model.NewsletterEnabled || Model.CustomerAttributes.Count > 0)
            {
                <div class="fieldset">
                    <legend>@T("Account.Options")</legend>
                    <div class="form-fields">
                        @if (Model.NewsletterEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Newsletter, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.EditorFor(model => model.Newsletter)
                                </div>
                                <div class="col-md-4">
                                    @Html.ValidationMessageFor(model => model.Newsletter)
                                </div>
                            </div>
                        }
                        @if (Model.CustomerAttributes.Count > 0)
                        {
                            @Html.Partial("_CustomerAttributes", Model.CustomerAttributes)
                        }
                    </div>
                </div>
            }
            if (Model.AllowCustomersToSetTimeZone || Model.SignatureEnabled)
            {
                <div class="fieldset">
                    <legend>@T("Account.Preferences")</legend>
                    <div class="form-fields">
                        @if (Model.AllowCustomersToSetTimeZone)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.TimeZoneId, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.DropDownList("TimeZoneId", Model.AvailableTimeZones)
                                </div>
                                <div class="col-md-4">
                                    @Html.ValidationMessageFor(model => model.TimeZoneId)
                                </div>
                            </div>
                        }
                        @if (Model.SignatureEnabled)
                        {
                            <div class="form-group row">
                                @Html.LabelFor(model => model.Signature, new { @class = "col-md-2 control-label" }, ":")
                                <div class="col-md-6">
                                    @Html.TextAreaFor(model => model.Signature, new { @class = "form-control" })
                                </div>
                            </div>
                        }
                    </div>
                </div>
            }

            if (Model.NumberOfExternalAuthenticationProviders > 0)
            {
                <div class="fieldset">
                    <legend>@T("Account.AssociatedExternalAuth")</legend>
                    @if (Model.AssociatedExternalAuthRecords.Count > 0)
                    {
                        //existing associated external records
                        <table class="data-table">
                            <colgroup>
                                <col />
                                <col />
                                <col />
                            </colgroup>
                            <thead>
                                <tr>
                                    <th class="a-center auth-method-name">
                                        @T("Account.AssociatedExternalAuth.AuthMethodName")
                                    </th>
                                    <th class="a-center email">
                                        @T("Account.AssociatedExternalAuth.Email")
                                    </th>
                                    <th class="a-center external-id">
                                        @T("Account.AssociatedExternalAuth.ExternalIdentifier")
                                    </th>
                                    <th class="a-center remove">
                                        @T("Account.AssociatedExternalAuth.Remove")
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model.AssociatedExternalAuthRecords)
                                {
                                    <tr>
                                        <td class="a-left auth-method-name">
                                            @item.AuthMethodName
                                        </td>
                                        <td class="a-left email">
                                            @item.Email
                                        </td>
                                        <td class="a-left external-id">
                                            @CommonHelper.EnsureMaximumLength(item.ExternalIdentifier, 40, "...")
                                        </td>
                                        <td class="a-center remove">
                                            <a href="@Url.Action("RemoveExternalAssociation", "Customer", new { id = item.Id })">@T("Account.AssociatedExternalAuth.Remove")</a>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    }

                    @if (Model.NumberOfExternalAuthenticationProviders > Model.AssociatedExternalAuthRecords.Count)
                    {
                        //we can add more external records
                        <div class="form-fields add-more-external-records">
                            @T("Account.AssociatedExternalAuth.AddMoreRecords") <a href="@Url.RouteUrl("Login", null, "http")">@Url.RouteUrl("Login", null, "http")</a>
                        </div>
                    }
                </div>
            }
            <div class="buttons">
                <input type="submit" value="@T("Common.Save")" name="save-info-button" class="btn btn-default" />
            </div>
        }
    </div>
</div>
